import { Equal, Hash } from "effect";

class Person implements Equal.Equal {
  constructor(
    readonly id: number, // Unique identifier for each person
    readonly name: string,
    readonly age: number,
  ) {}

  // Defines equality based on id, name, and age
  [Equal.symbol](that: Equal.Equal): boolean {
    if (that instanceof Person) {
      return (
        Equal.equals(this.id, that.id) &&
        Equal.equals(this.name, that.name) &&
        Equal.equals(this.age, that.age)
      );
    }
    return false;
  }

  // Generates a hash code based primarily on the unique id
  [Hash.symbol](): number {
    return Hash.hash(this.id);
  }
}

const alice = new Person(1, "Alice", 30);
console.log(Equal.equals(alice, new Person(1, "Alice", 30)));
// Output: true

const bob = new Person(2, "Bob", 40);
console.log(Equal.equals(alice, bob));
// Output: false
